package someTestExcemple.huaweiOd.string;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexExample {
    // 正则表达式学习
    public static void main(String[] args) {
        // 定义一个正则表达式
        String regex = "\\d+"; // 匹配一个或多个数字
        String input = "Hello 123 World 456";

        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);

        // 创建匹配器
        Matcher matcher = pattern.matcher(input);
        // 查找匹配项
        while (matcher.find()) {
            System.out.println("Found: " + matcher.group());
        }

        String email = "example@example.com";
        String regex1 = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";

        boolean isValid = email.matches(regex1);
        System.out.println("Is valid email? " + isValid);
    }
}
